Skip to content

fix: treat omitted SSE event type as default 'message' in WebClientStreamableHttpTransport#5788

Closed
anuragg-saxenaa wants to merge 1 commit intospring-projects:mainfrom
anuragg-saxenaa:fix/issue-5780-sse-default-message-event
Closed

fix: treat omitted SSE event type as default 'message' in WebClientStreamableHttpTransport#5788
anuragg-saxenaa wants to merge 1 commit intospring-projects:mainfrom
anuragg-saxenaa:fix/issue-5780-sse-default-message-event

Conversation

@anuragg-saxenaa
Copy link
Copy Markdown

Problem

WebClientStreamableHttpTransport.parse() only processes SSE frames where event.event() equals "message". Per the SSE specification, omitting the event: field means the event type defaults to "message". When Spring/WebFlux decodes such a frame, ServerSentEvent.event() returns null — so the frame was silently dropped.

This caused MCP clients to miss valid JSON-RPC responses from servers that emit bare data:-only SSE frames, resulting in initialization timeouts like:

  • Client failed to initialize by explicit API call
  • Did not observe any item or terminal signal within ...

This is the Spring AI counterpart of modelcontextprotocol/java-sdk#885 / PR #913, which fixed the HttpClient variant but explicitly noted the WebClient variant needed a separate fix here.

Fix

Accept all three equivalent event types for SSE message frames:

  • event == null (field omitted)
  • event == "" (field present but empty)
  • event == "message" (explicit)
String eventType = event.event();
if (eventType == null || eventType.isEmpty() || MESSAGE_EVENT_TYPE.equals(eventType)) {

Testing

Added testSseFrameWithoutEventTypeIsAccepted() to WebClientStreamableHttpTransportErrorHandlingIT — spins up a local HTTP server that returns an SSE stream with only a data: line (no event: line) and verifies the message handler receives the parsed JSON-RPC message.

Closes #5780

Per the SSE specification, a frame that omits the `event:` field defaults
to event type `message`. WebClientStreamableHttpTransport previously only
accepted frames where event.event() was exactly "message", silently
dropping frames where event.event() was null or empty.

This caused MCP clients to miss valid JSON-RPC responses from servers that
emit bare `data:`-only SSE frames, leading to initialization timeouts.

Fixes spring-projects#5780

Signed-off-by: anuragg-saxenaa <anuragg.saxenaa@gmail.com>
@redinside-dev
Copy link
Copy Markdown

Hi maintainers 👋 This PR has been waiting for review for 13 days. Happy to make any adjustments — just let me know! Targeting Sprint 1 close by Apr 25.

@anuragg-saxenaa
Copy link
Copy Markdown
Author

Closing this PR. Apologies for the noise — going forward all contributions will go through proper human review before submission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebClientStreamableHttpTransport drops valid SSE frames when event: is omitted (should default to message)

2 participants